{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "离散型随机变量样本： [1 1 1 0 1 1 1 0 1 1 1 0 0 0 0 0 1 1 1 1 1 0 1 1 1 1 0 1 1 1 1 1 1 1 1 0 1\n",
      " 1 1 0 1 1 1 1 1 1 0 1 1 1 1 1 1 0 1 1 0 1 0 1 1 1 0 0 1 1 1 1 1 1 0 1 0 0\n",
      " 1 0 1 1 0 1 0 1 0 1 0 0 1 0 1 0 1 0 1 1 0 1 0 0 0 0]\n",
      "连续型随机变量样本： [1 1 1 0 1 1 1 0 1 1 1 0 0 0 0 0 1 1 1 1 1 0 1 1 1 1 0 1 1 1 1 1 1 1 1 0 1\n",
      " 1 1 0 1 1 1 1 1 1 0 1 1 1 1 1 1 0 1 1 0 1 0 1 1 1 0 0 1 1 1 1 1 1 0 1 0 0\n",
      " 1 0 1 1 0 1 0 1 0 1 0 0 1 0 1 0 1 0 1 1 0 1 0 0 0 0]\n",
      "简单随机抽样结果： [1 1 1 0 1 1 1 0 1 1 1 0 0 0 0 0 1 1 1 1 1 0 1 1 1 1 0 1 1 1 1 1 1 1 1 0 1\n",
      " 1 1 0 1 1 1 1 1 1 0 1 1 1 1 1 1 0 1 1 0 1 0 1 1 1 0 0 1 1 1 1 1 1 0 1 0 0\n",
      " 1 0 1 1 0 1 0 1 0 1 0 0 1 0 1 0 1 0 1 1 0 1 0 0 0 0]\n",
      "参数估计值（极大似然估计）： 0.66\n",
      "似然函数值： 1.65280833820127e-45\n"
     ]
    }
   ],
   "source": [
    "import numpy as np\n",
    "from scipy.stats import norm, poisson\n",
    "\n",
    "# 离散型随机变量（泊松分布）\n",
    "lambda_value = 2  # 泊松分布的参数\n",
    "rv = poisson(mu=lambda_value)  # 创建泊松分布的实例\n",
    "data = rv.rvs(size=100)  # 从泊松分布中抽取100个样本\n",
    "\n",
    "# 连续型随机变量（正态分布）\n",
    "mu = 0  # 正态分布的均值\n",
    "sigma = 1  # 正态分布的标准差\n",
    "rv = norm(loc=mu, scale=sigma)  # 创建正态分布的实例\n",
    "data = rv.rvs(size=100)  # 从正态分布中抽取100个样本\n",
    "\n",
    "# 简单随机抽样\n",
    "data = np.random.choice([0, 1], size=100, p=[0.3, 0.7])  # 从给定的样本中进行简单随机抽样\n",
    "\n",
    "# 似然函数和极大似然估计\n",
    "mu_hat = np.mean(data)  # 使用样本均值作为参数估计值（极大似然估计）\n",
    "likelihood = np.prod(norm.pdf(data, loc=mu_hat, scale=sigma))  # 计算似然函数值\n",
    "\n",
    "print(\"离散型随机变量样本：\", data)\n",
    "print(\"连续型随机变量样本：\", data)\n",
    "print(\"简单随机抽样结果：\", data)\n",
    "print(\"参数估计值（极大似然估计）：\", mu_hat)\n",
    "print(\"似然函数值：\", likelihood)\n"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
